home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / audiol1a / module1.bas < prev    next >
Encoding:
BASIC Source File  |  1998-04-14  |  53.0 KB  |  830 lines

  1. Attribute VB_Name = "Module1"
  2. Option Explicit
  3.  
  4. Public Const CALLBACK_FUNCTION = &H30000
  5. Public Const MM_WIM_DATA = &H3C0
  6. Public Const WHDR_DONE = &H1         '  done bit
  7. Public Const GMEM_FIXED = &H0         ' Global Memory Flag used by GlobalAlloc functin
  8.  
  9. Type WAVEHDR
  10. ' The WAVEHDR user-defined type defines the header used to identify a waveform-audio buffer.
  11.    lpData As Long          ' Address of the waveform buffer.
  12.    dwBufferLength As Long  ' Length, in bytes, of the buffer.
  13.    dwBytesRecorded As Long ' When the header is used in input, this member specifies how much
  14.                            ' data is in the buffer.
  15.  
  16.    dwUser As Long          ' User data.
  17.    dwFlags As Long         ' Flags supplying information about the buffer. Set equal to zero.
  18.    dwLoops As Long         ' Number of times to play the loop. Set equal to zero.
  19.    lpNext As Long          ' Not used
  20.    Reserved As Long        ' Not used
  21. End Type
  22.  
  23. Type WAVEINCAPS
  24. ' The WAVEINCAPS user-defined variable describes the capabilities of a waveform-audio input
  25. ' device.
  26.    wMid As Integer         ' Manufacturer identifier for the device driver for the
  27.                            ' waveform-audio input device. Manufacturer identifiers
  28.                            ' are defined in Manufacturer and Product Identifiers in
  29.                            ' the Platform SDK product documentation.
  30.    wPid As Integer         ' Product identifier for the waveform-audio input device.
  31.                            ' Product identifiers are defined in Manufacturer and Product
  32.                            ' Identifiers in the Platform SDK product documentation.
  33.    vDriverVersion As Long  ' Version number of the device driver for the
  34.                            ' waveform-audio input device. The high-order byte
  35.                            ' is the major version number, and the low-order byte
  36.                            ' is the minor version number.
  37.    szPname As String * 32  ' Product name in a null-terminated string.
  38.    dwFormats As Long       ' Standard formats that are supported. See the Platform
  39.                            ' SDK product documentation for more information.
  40.    wChannels As Integer    ' Number specifying whether the device supports
  41.                            ' mono (1) or stereo (2) input.
  42. End Type
  43.  
  44. Type WAVEFORMAT
  45. ' The WAVEFORMAT user-defined type describes the format of waveform-audio data. Only
  46. ' format information common to all waveform-audio data formats is included in this
  47. ' user-defined type.
  48.    wFormatTag As Integer      ' Format type. Use the constant WAVE_FORMAT_PCM Waveform-audio data
  49.                               ' to define the data as PCM.
  50.    nChannels As Integer       ' Number of channels in the waveform-audio data. Mono data uses one
  51.                               ' channel and stereo data uses two channels.
  52.    nSamplesPerSec As Long     ' Sample rate, in samples per second.
  53.    nAvgBytesPerSec As Long    ' Required average data transfer rate, in bytes per second. For
  54.                               ' example, 16-bit stereo at 44.1 kHz has an average data rate of
  55.                               ' 176,400 bytes per second (2 channels ù 2 bytes per sample per
  56.                               ' channel ù 44,100 samples per second).
  57.    nBlockAlign As Integer     ' Block alignment, in bytes. The block alignment is the minimum atomic unit of data. For PCM data, the block alignment is the number of bytes used by a single sample, including data for both channels if the data is stereo. For example, the block alignment for 16-bit stereo PCM is 4 bytes (2 channels ù 2 bytes per sample).
  58.    wBitsPerSample As Integer  ' For buffer estimation
  59.    cbSize As Integer          ' Block size of the data.
  60. End Type
  61.  
  62. Declare Function waveInOpen Lib "winmm.dll" (lphWaveIn As Long, _
  63.                                              ByVal uDeviceID As Long, _
  64.                                              lpFormat As WAVEFORMAT, _
  65.                                              ByVal dwCallback As Long, _
  66.                                              ByVal dwInstance As Long, _
  67.                                              ByVal dwFlags As Long) As Long
  68. ' The waveInOpen function opens the given waveform-audio input device for recording. The function
  69. ' uses the following parameters
  70. '     lphWaveIn-  a long value that is the handle identifying the open waveform-audio input
  71. '                 device. Use this handle to identify the device when calling other
  72. '                 waveform-audio input functions. This parameter can be NULL if WAVE_FORMAT_QUERY
  73. '                 is specified for fdwOpen.
  74. '     uDeviceID-  a long value that identifies the waveform-audio input device to open.
  75. '                 This parameter can be either a device identifier or a handle of an open
  76. '                 waveform-audio input device.
  77. '     lpFormat-   the WAVEFORMAT user-defined typed that identifies the desired format for
  78. '                 recording waveform-audio data.
  79. '     dwCallback- a long value that is an event handle, a handle to a window, or the identifier
  80. '                 of a thread to be called during waveform-audio recording to process messages
  81. '                 related to the progress of recording. If no callback function is required,
  82. '                 this value can be zero. For more information on the callback function,
  83. '                 see waveInProc.
  84. '     dwCallback- a long value that is the user-instance data passed to the callback mechanism.
  85. '                 This parameter is not used with the window callback mechanism.
  86. '     dwFlags-    Flags for opening the device. The following values are defined:
  87. '                 CALLBACK_EVENT (&H50000)-event handle.
  88. '                 CALLBACK_FUNCTION (&H30000)-callback procedure address.
  89. '                 CALLBACK_NULL (&H00000)-No callback mechanism. This is the default setting.
  90. '                 CALLBACK_THREAD (&H20000)-thread identifier.
  91. '                 CALLBACK_WINDOW (&H10000)-window handle.
  92. '                 WAVE_FORMAT_DIRECT (&H8)-ACM driver does not perform conversions on the
  93. '                                            audio data.
  94. '                 WAVE_FORMAT_QUERY (&H1)-queries the device to determine whether it supports
  95. '                                         the given format, but it does not open the device.
  96. '                 WAVE_MAPPED (&H4)-The uDeviceID parameter specifies a waveform-audio device
  97. '                                   to be mapped to by the wave mapper.
  98.  
  99. Declare Function waveInPrepareHeader Lib "winmm.dll" (ByVal hWaveIn As Long, _
  100.                                                       lpWaveInHdr As WAVEHDR, _
  101.                                                       ByVal uSize As Long) As Long
  102. ' The waveInPrepareHeader function prepares a buffer for waveform-audio input. The function
  103. ' uses the following parameters:
  104. '     hWaveIn-    a long value that is the handle of the waveform-audio input device.
  105. '     lpWaveInHdr-the WAVEHDR user-defined type variable.
  106. '     uSize-      the size in bytes of the WAVEHDR user-defined type variable. Use the
  107. '                 results of the Len function for this parameter.
  108.  
  109.  
  110. Declare Function waveInReset Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
  111. ' The waveInReset function stops input on the given waveform-audio input device and resets
  112. ' the current position to zero. All pending buffers are marked as done and returned to
  113. ' the application. The function requires the handle to the waveform-audio input device.
  114.  
  115. Declare Function waveInStart Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
  116. ' The waveInStart function starts input on the given waveform-audio input device. The function
  117. ' requires the handle of the waveform-audio input device.
  118.  
  119. Declare Function waveInStop Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
  120. ' The waveInStop function stops waveform-audio input. The function requires the handle of
  121. ' the waveform-audio input device.
  122.  
  123. Declare Function waveInUnprepareHeader Lib "winmm.dll" _
  124.                                           (ByVal hWaveIn As Long, _
  125.                                           lpWaveInHdr As WAVEHDR, _
  126.                                           ByVal uSize As Long) As Long
  127. ' The waveInUnprepareHeader function cleans up the preparation performed by the
  128. ' waveInPrepareHeader function. This function must be called after the device driver
  129. ' fills a buffer and returns it to the application. You must call this function before
  130. ' freeing the buffer. The function uses the following parameters:
  131. '     hWaveIn-       a long value that is the handle of the waveform-audio input device.
  132. '     lpWaveInHdr-   the variable typed as the WAVEHDR user-defined type identifying the
  133. '                    buffer to be cleaned up.
  134. '     uSize-         a long value that is the size in bytes, of the WAVEHDR varaible. Use
  135. '                    the Len function with the WAVEHDR variable as the argument to get this
  136. '                    value.
  137.  
  138. Declare Function waveInClose Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
  139. ' The waveInClose function closes the given waveform-audio input device. The function
  140. ' requires the handle of the waveform-audio input device. If the function succeeds,
  141. ' the handle is no longer valid after this call.
  142.  
  143. Declare Function waveInGetDevCaps Lib "winmm.dll" Alias "waveInGetDevCapsA" _
  144.                   (ByVal uDeviceID As Long, _
  145.                   lpCaps As WAVEINCAPS, _
  146.                   ByVal uSize As Long) As Long
  147. ' This function retrieves the capabilities of a given waveform-audio input device. You can
  148. ' use this function to determine the number of waveform-audio input devices present in the
  149. ' system. If the value specified by the uDeviceID parameter is a device identifier,
  150. ' it can vary from zero to one less than the number of devices present. The function uses
  151. ' the following parameters
  152. '     uDeviceID-     long value that identifies waveform-audio output device. This value can be
  153. '                    either a device identifier or a handle of an open waveform-audio input device.
  154. '     lpCaps-user-   defined variable containing information about the capabilities of the device.
  155. '     uSize-         the size in bytes of the user-defined variable used as the lpCaps parameter.
  156. '                    Use the Len function to get this value.
  157.  
  158. Declare Function waveInGetNumDevs Lib "winmm.dll" () As Long
  159. ' The waveInGetNumDevs function returns the number of waveform-audio input devices present in the system.
  160.  
  161. Declare Function waveInGetErrorText Lib "winmm.dll" Alias "waveInGetErrorTextA" _
  162.                      (ByVal err As Long, _
  163.                      ByVal lpText As String, _
  164.                      ByVal uSize As Long) As Long
  165. 'The waveInGetErrorText function retrieves a textual description of the error identified by
  166. ' the given error number. The function uses the following parameters:
  167. '     Err-     a long value that is the error number.
  168. '     lpText-  a string variable that contains the textual error description.
  169. '     uSize-   the size in characters of the lpText string variable.
  170.  
  171. Declare Function waveInAddBuffer Lib "winmm.dll" (ByVal hWaveIn As Long, _
  172.                                                    lpWaveInHdr As WAVEHDR, _
  173.                                                    ByVal uSize As Long) As Long
  174. ' The waveInAddBuffer function sends an input buffer to the given waveform-audio input device.
  175. ' The function uses the following parameters:
  176. '     hWaveIn-       a long value that is the handle of the waveform-audio input device.
  177. '     lpWaveInHdr-   the variable typed as the WAVEHDR user-defined type.
  178. '     uSize-         a long value that is the size in bytes of the variable typed as the
  179. '                    WAVEHDR user-defined variable. Use the Len function with the WAVEHDR
  180. '                    variable as the argument to get this value.
  181.  
  182.  
  183. Public Const MMSYSERR_NOERROR = 0
  184. Public Const MAXPNAMELEN = 32
  185.  
  186. Public Const MIXER_LONG_NAME_CHARS = 64
  187. Public Const MIXER_SHORT_NAME_CHARS = 16
  188. Public Const MIXER_GETLINEINFOF_COMPONENTTYPE = &H3&
  189. Public Const MIXER_GETCONTROLDETAILSF_VALUE = &H0&
  190. Public Const MIXER_GETLINECONTROLSF_ONEBYTYPE = &H2&
  191.  
  192. Public Const MIXERLINE_COMPONENTTYPE_DST_FIRST = &H0&
  193. Public Const MIXERLINE_COMPONENTTYPE_SRC_FIRST = &H1000&
  194. Public Const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 4)
  195. Public Const MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 3)
  196. Public Const MIXERLINE_COMPONENTTYPE_SRC_LINE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 2)
  197.  
  198. Public Const MIXERCONTROL_CT_CLASS_FADER = &H50000000
  199. Public Const MIXERCONTROL_CT_UNITS_UNSIGNED = &H30000
  200. Public Const MIXERCONTROL_CT_UNITS_SIGNED = &H20000
  201. Public Const MIXERCONTROL_CT_CLASS_METER = &H10000000
  202. Public Const MIXERCONTROL_CT_SC_METER_POLLED = &H0&
  203. Public Const MIXERCONTROL_CONTROLTYPE_FADER = (MIXERCONTROL_CT_CLASS_FADER Or MIXERCONTROL_CT_UNITS_UNSIGNED)
  204. Public Const MIXERCONTROL_CONTROLTYPE_VOLUME = (MIXERCONTROL_CONTROLTYPE_FADER + 1)
  205. Public Const MIXERLINE_COMPONENTTYPE_DST_WAVEIN = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 7)
  206. Public Const MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 8)
  207. Public Const MIXERCONTROL_CONTROLTYPE_SIGNEDMETER = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_SIGNED)
  208. Public Const MIXERCONTROL_CONTROLTYPE_PEAKMETER = (MIXERCONTROL_CONTROLTYPE_SIGNEDMETER + 1)
  209.  
  210. Declare Function mixerClose Lib "winmm.dll" (ByVal hmx As Long) As Long
  211. ' The mixerClose function closes the specified mixer device. The function requires the
  212. ' handle of the mixer device. This handle must have been returned successfully by the
  213. ' mixerOpen function. If mixerClose is successful, the handle is no longer valid.
  214.  
  215. Declare Function mixerGetControlDetails Lib "winmm.dll" Alias "mixerGetControlDetailsA" _
  216.             (ByVal hmxobj As Long, _
  217.             pMxcd As MIXERCONTROLDETAILS, _
  218.             ByVal fdwDetails As Long) As Long
  219. ' The mixerGetControlDetails function retrieves details about a single control associated
  220. ' with an audio line. the function uses the following parameters:
  221. '     hmxobj-     a long value that is the handle to the mixer device object being queried.
  222. '     pMxcd-      the variable defined as the MIXERCONTROLDETAILS user-defined type.
  223. '     fdwDetails- Flags for retrieving control details. The following values are defined:
  224. '                    MIXER_GETCONTROLDETAILSF_LISTTEXT-The paDetails member of the
  225. '                       MIXERCONTROLDETAILS user-defined variable points to one or more
  226. '                       MIXERCONTROLDETAILS_LISTTEXT user-defined variables to receive text
  227. '                       labels for multiple-item controls. An application must get all list
  228. '                       text items for a multiple-item control at once. This flag cannot be
  229. '                       used with MIXERCONTROL_CONTROLTYPE_CUSTOM controls.
  230. '                    MIXER_GETCONTROLDETAILSF_VALUE-Current values for a control are
  231. '                       retrieved. The paDetails member of the MIXERCONTROLDETAILS user-defined
  232. '                       variable points to one or more details appropriate for the control class.
  233. '                    MIXER_OBJECTF_AUX (&H50000000)-The hmxobj parameter is an auxiliary device
  234. '                       identifier in the range of zero to one less than the number of devices
  235. '                       returned by the auxGetNumDevs function.
  236. '                    MIXER_OBJECTF_HMIDIIN (MIXER_OBJECTF_HANDLE or MIXER_OBJECTF_MIDIIN)-
  237. '                       The hmxobj parameter is the handle of a MIDI (Musical Instrument Digital
  238. '                       Interface) input device. This handle must have been returned by the
  239. '                       midiInOpen function.
  240. '                    MIXER_OBJECTF_HMIDIOUT (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIOUT)-The
  241. '                       hmxobj parameter is the handle of a MIDI output device. This handle must
  242. '                       have been returned by the midiOutOpen function.
  243. '                    MIXER_OBJECTF_HMIXER (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIXER)-The
  244. '                       hmxobj parameter is a mixer device handle returned by the mixerOpen
  245. '                       function. This flag is optional.
  246. '                    MIXER_OBJECTF_HWAVEIN (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEIN)-The
  247. '                       hmxobj parameter is a waveform-audio input handle returned by the
  248. '                       waveInOpen function.
  249. '                    MIXER_OBJECTF_HWAVEOUT ((MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEOUT)-The
  250. '                       hmxobj parameter is a waveform-audio output handle returned by the
  251. '                       waveOutOpen function.
  252. '                    MIXER_OBJECTF_MIDIIN (&H40000000L)-The hmxobj parameter is the identifier
  253. '                       of a MIDI input device. This identifier must be in the range of zero to
  254. '                       one less than the number of devices returned by the midiInGetNumDevs
  255. '                       function.
  256. '                    MIXER_OBJECTF_MIDIOUT (&H30000000)-The hmxobj parameter is the identifier
  257. '                       of a MIDI output device. This identifier must be in the range of zero
  258. '                       to one less than the number of devices returned by the midiOutGetNumDevs
  259. '                       function.
  260. '                    MIXER_OBJECTF_MIXER (&H00000000)-The hmxobj parameter is the identifier of a
  261. '                       mixer device in the range of zero to one less than the number of devices
  262. '                       returned by the mixerGetNumDevs function. This flag is optional.
  263. '                    MIXER_OBJECTF_WAVEIN (&H20000000)-The hmxobj parameter is the identifier of a
  264. '                       waveform-audio input device in the range of zero to one less than the
  265. '                       number of devices returned by the waveInGetNumDevs function.
  266. '                    MIXER_OBJECTF_WAVEOUT (&H10000000)-The hmxobj parameter is the identifier of a
  267. '                       waveform-audio output device in the range of zero to one less than the
  268. '                       number of devices returned by the waveOutGetNumDevs function.
  269.  
  270. Declare Function mixerGetDevCaps Lib "winmm.dll" Alias "mixerGetDevCapsA" _
  271.                   (ByVal uMxId As Long, _
  272.                   ByVal pmxcaps As MIXERCAPS, _
  273.                   ByVal cbmxcaps As Long) As Long
  274. ' The mixerGetDevCaps function queries a specified mixer device to determine its capabilities.
  275. ' The function uses the following parameters:
  276. '     uMxId-      a long value that is the handle of an open mixer device.
  277. '     pmxcaps-    a variable defined as the MIXERCAPS user-defined type to contain information
  278. '                 about the capabilities of the device.
  279. '     cbmxcaps-   a long value that is the size in bytes, of the variable defined as the
  280. '                 MIXERCAPS user-defined type. Use the Len functions with the MIXERCAPS variable
  281. '                 as the argument to get this value.
  282.  
  283. Declare Function mixerGetID Lib "winmm.dll" (ByVal hmxobj As Long, _
  284.                                              pumxID As Long, _
  285.                                              ByVal fdwId As Long) As Long
  286. ' The mixerGetID function retrieves the device identifier for a mixer device associated
  287. ' with a specified device handle.The function uses the following parameters:
  288. '     hmxobj-  a long value that is the handle of the audio mixer object to map to a
  289. '              mixer device identifier.
  290. '     pumxID-  the long value to contain the mixer device identifier. If no mixer device
  291. '              is available for the hmxobj object, the value û 1 is placed in this location
  292. '              and the MMSYSERR_NODRIVER error value is returned.
  293. '     fdwId-   Flags for mapping the mixer object hmxobj. The following values are defined:
  294. '                 MIXER_OBJECTF_AUX (&H50000000)-The hmxobj parameter is an auxiliary device
  295. '                       identifier in the range of zero to one less than the number of devices
  296. '                       returned by the auxGetNumDevs function.
  297. '                 MIXER_OBJECTF_HMIDIIN (MIXER_OBJECTF_HANDLE or MIXER_OBJECTF_MIDIIN)-
  298. '                       the hmxobj parameter is the handle of a MIDI input device. This handle
  299. '                       must have been returned by the midiInOpen function.
  300. '                 MIXER_OBJECTF_HMIDIOUT (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIOUT)-The
  301. '                       hmxobj parameter is the handle of a MIDI output device. This handle must
  302. '                       have been returned by the midiOutOpen function.
  303. '                 MIXER_OBJECTF_HMIXER (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIXER)-The hmxobj
  304. '                       parameter is a mixer device handle returned by the mixerOpen function.
  305. '                       This flag is optional.
  306. '                 MIXER_OBJECTF_HWAVEIN (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEIN)-The
  307. '                       hmxobj parameter is a waveform-audio input handle returned by the
  308. '                       waveInOpen function.
  309. '                 MIXER_OBJECTF_HWAVEOUT ((MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEOUT)-The
  310. '                       hmxobj parameter is a waveform-audio output handle returned by the
  311. '                       waveOutOpen function.
  312. '                 MIXER_OBJECTF_MIDIIN (&H40000000L)-The hmxobj parameter is the identifier of
  313. '                       a MIDI input device. This identifier must be in the range of zero to
  314. '                       one less than the number of devices returned by the midiInGetNumDevs
  315. '                       function.
  316. '                 MIXER_OBJECTF_MIDIOUT (&H30000000)-The hmxobj parameter is the identifier of
  317. '                       a MIDI output device. This identifier must be in the range of zero to
  318. '                       one less than the number of devices returned by the midiOutGetNumDevs
  319. '                       function.
  320. '                 MIXER_OBJECTF_MIXER (&H00000000)-The hmxobj parameter is the identifier of
  321. '                       a mixer device in the range of zero to one less than the number of
  322. '                       devices returned by the mixerGetNumDevs function. This flag is optional.
  323. '                 MIXER_OBJECTF_WAVEIN (&H20000000)-The hmxobj parameter is the identifier of a
  324. '                       waveform-audio input device in the range of zero to one less than the
  325. '                       number of devices returned by the waveInGetNumDevs function.
  326. '                 MIXER_OBJECTF_WAVEOUT (&H10000000)-The hmxobj parameter is the identifier of a
  327. '                       waveform-audio output device in the range of zero to one less than the
  328. '                       number of devices returned by the waveOutGetNumDevs function.
  329.  
  330. Declare Function mixerGetLineControls Lib "winmm.dll" Alias "mixerGetLineControlsA" _
  331.                   (ByVal hmxobj As Long, _
  332.                   pmxlc As MIXERLINECONTROLS, _
  333.                   ByVal fdwControls As Long) As Long
  334. ' The mixerGetLineControls function retrieves one or more controls associated with an audio
  335. ' line. The function uses the following parameters:
  336. '     hmxobj-        a long value that is the handle of the mixer device object that is being
  337. '                    queried.
  338. '     pmxlc-         the variable defined as the MIXERLINECONTROLS user-defined type used to
  339. '                    reference one or more variables defined as theMIXERCONTROL user-defined
  340. '                    types to be filled with information about the controls associated with
  341. '                    an audio line. The cbStruct member of the MIXERLINECONTROLS variable
  342. '                    must always be initialized to be the size, in bytes, of the
  343. '                    MIXERLINECONTROLS variable.
  344. '     fdwControls-   Flags for retrieving information about one or more controls associated w
  345. '                    with an audio line. The following values are defined:
  346. '                    MIXER_GETLINECONTROLSF_ALL-The pmxlc parameter references a list of
  347. '                       MIXERCONTROL variables that will receive information on all controls
  348. '                       associated with the audio line identified by the dwLineID member of
  349. '                       the MIXERLINECONTROLS structure. The cControls member must be initialized
  350. '                       to the number of controls associated with the line. This number is
  351. '                       retrieved from the cControls member of the MIXERLINE structure returned
  352. '                       by the mixerGetLineInfo function. The cbmxctrl member must be
  353. '                       initialized to the size, in bytes, of a single MIXERCONTROL variable.
  354. '                       The pamxctrl member must point to the first MIXERCONTROL variable to be
  355. '                       filled. The dwControlID and dwControlType members are ignored for this
  356. '                       query.
  357. '                    MIXER_GETLINECONTROLSF_ONEBYID-The pmxlc parameter references a single
  358. '                       MIXERCONTROL variable that will receive information on the control
  359. '                       identified by the dwControlID member of the MIXERLINECONTROLS variable.
  360. '                       The cControls member must be initialized to 1. The cbmxctrl member must
  361. '                       be initialized to the size, in bytes, of a single MIXERCONTROL variable.
  362. '                       The pamxctrl member must point to a MIXERCONTROL structure to be filled.
  363. '                       The dwLineID and dwControlType members are ignored for this query. This
  364. '                       query is usually used to refresh a control after receiving a
  365. '                       MM_MIXM_CONTROL_CHANGE control change notification message by the
  366. '                       user-defined callback (see mixerOpen).
  367. '                    MIXER_GETLINECONTROLSF_ONEBYTYPE-The mixerGetLineControls function
  368. '                       retrieves information about the first control of a specific class for
  369. '                       the audio line that is being queried. The pmxlc parameter references a
  370. '                       single MIXERCONTROL structure that will receive information about the
  371. '                       specific control. The audio line is identified by the dwLineID member.
  372. '                       The control class is specified in the dwControlType member of the
  373. '                       MIXERLINECONTROLS variable. The dwControlID member is ignored for this
  374. '                       query. This query can be used by an application to get information on
  375. '                       a single control associated with a line. For example, you might want
  376. '                       your application to use a peak meter only from a waveform-audio output
  377. '                       line.
  378. '                    MIXER_OBJECTF_AUX (&H50000000)-The hmxobj parameter is an auxiliary device
  379. '                       identifier in the range of zero to one less than the number of devices
  380. '                       returned by the auxGetNumDevs function.
  381. '                    MIXER_OBJECTF_HMIDIIN (MIXER_OBJECTF_HANDLE or MIXER_OBJECTF_MIDIIN)-The
  382. '                       hmxobj parameter is the handle of a MIDI input device. This handle must
  383. '                       have been returned by the midiInOpen function.
  384. '                    MIXER_OBJECTF_HMIDIOUT (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIOUT)-The
  385. '                       hmxobj parameter is the handle of a MIDI output device. This handle must
  386. '                       have been returned by the midiOutOpen function.
  387. '                    MIXER_OBJECTF_HMIXER (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIXER)-The
  388. '                       hmxobj parameter is a mixer device handle returned by the mixerOpen
  389. '                       function. This flag is optional.
  390. '                    MIXER_OBJECTF_HWAVEIN (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEIN)-The
  391. '                       hmxobj parameter is a waveform-audio input handle returned by the
  392. '                       waveInOpen function.
  393. '                    MIXER_OBJECTF_HWAVEOUT ((MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEOUT)-The
  394. '                       hmxobj parameter is a waveform-audio output handle returned by the
  395. '                       waveOutOpen function.
  396. '                    MIXER_OBJECTF_MIDIIN (&H40000000L)-The hmxobj parameter is the identifier of
  397. '                       a MIDI input device. This identifier must be in the range of zero to one
  398. '                       less than the number of devices returned by the midiInGetNumDevs function.
  399. '                    MIXER_OBJECTF_MIDIOUT (&H30000000)-The hmxobj parameter is the identifier of
  400. '                       a MIDI output device. This identifier must be in the range of zero to one
  401. '                       less than the number of devices returned by the midiOutGetNumDevs function.
  402. '                    MIXER_OBJECTF_MIXER (&H00000000)-The hmxobj parameter is the identifier of a
  403. '                       mixer device in the range of zero to one less than the number of devices
  404. '                       returned by the mixerGetNumDevs function. This flag is optional.
  405. '                    MIXER_OBJECTF_WAVEIN (&H20000000)-The hmxobj parameter is the identifier of a
  406. '                       waveform-audio input device in the range of zero to one less than the
  407. '                       number of devices returned by the waveInGetNumDevs function.
  408. '                    MIXER_OBJECTF_WAVEOUT (&H10000000)-The hmxobj parameter is the identifier of a
  409. '                       waveform-audio output device in the range of zero to one less than the
  410. '                       number of devices returned by the waveOutGetNumDevs function.
  411.  
  412. Declare Function mixerGetLineInfo Lib "winmm.dll" Alias "mixerGetLineInfoA" _
  413.                      (ByVal hmxobj As Long, _
  414.                      pmxl As MIXERLINE, _
  415.                      ByVal fdwInfo As Long) As Long
  416. ' The mixerGetLineInfo function retrieves information about a specific line of a mixer device.
  417. ' Uses the same parameters and constants as the mixerGetLineControls function.
  418.  
  419. Declare Function mixerGetNumDevs Lib "winmm.dll" () As Long
  420. ' The mixerGetNumDevs function retrieves the number of mixer devices present in the system.
  421.  
  422. Declare Function mixerMessage Lib "winmm.dll" (ByVal hmx As Long, _
  423.                                                 ByVal uMsg As Long, _
  424.                                                 ByVal dwParam1 As Long, _
  425.                                                 ByVal dwParam2 As Long) As Long
  426. ' The mixerMessage function sends a custom mixer driver message directly to a mixer driver.
  427. ' The function uses the following parameters:
  428. '     hmx-     a long value that is the handle of an open instance of a mixer device. This
  429. '              value is the result of the mixerOpen function.
  430. '     uMsg-    Custom mixer driver message to send to the mixer driver. This message must
  431. '              be above or equal to the MXDM_USER constant.
  432. '     dwParam1 and dwParam2-Arguments associated with the message being sent.
  433.  
  434. Declare Function mixerOpen Lib "winmm.dll" (phmx As Long, _
  435.                                              ByVal uMxId As Long, _
  436.                                              ByVal dwCallback As Long, _
  437.                                              ByVal dwInstance As Long, _
  438.                                              ByVal fdwOpen As Long) As Long
  439. ' The mixerOpen function opens a specified mixer device and ensures that the device will
  440. ' not be removed until the application closes the handle. the function uses the following
  441. ' parameters:
  442. '     phmx-       a long value that is the handle identifying the opened mixer device. Use
  443. '                 this handle to identify the device when calling other audio mixer functions.
  444. '                 This parameter cannot be NULL.
  445. '     uMxId-      a long value that identifies the mixer device to open. Use a valid device
  446. '                 identifier or any HMIXEROBJ (see the mixerGetID function for a description of
  447. '                 mixer object handles). A "mapper" for audio mixer devices does not currently
  448. '                 exist, so a mixer device identifier of û 1 is not valid.
  449. '     dwCallback- Handle of a window called when the state of an audio line and/or control
  450. '                 associated with the device being opened is changed. Specify zero for this
  451. '                 parameter if no callback mechanism is to be used.
  452. '     dwInstance- User instance data passed to the callback function. This parameter is not
  453. '                 used with window callback functions.
  454. '     fdwOpen-    Flags for opening the device. The following values are defined:
  455. '                    CALLBACK_WINDOW-  The dwCallback parameter is assumed to be a window handle.
  456. '                    MIXER_OBJECTF_AUX (&H50000000)-The uMxId parameter is an auxiliary device
  457. '                       identifier in the range of zero to one less than the number of devices
  458. '                       returned by the auxGetNumDevs function.
  459. '                    MIXER_OBJECTF_HMIDIIN (MIXER_OBJECTF_HANDLE or MIXER_OBJECTF_MIDIIN)-the
  460. '                       uMxId parameter is the handle of a MIDI input device. This handle must
  461. '                       have been returned by the midiInOpen function.
  462. '                    MIXER_OBJECTF_HMIDIOUT (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIOUT)-The
  463. '                       uMxId parameter is the handle of a MIDI output device. This handle must
  464. '                       have been returned by the midiOutOpen function.
  465. '                    MIXER_OBJECTF_HMIXER (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIXER)-The uMxId
  466. '                       parameter is a mixer device handle returned by the mixerOpen function.
  467. '                       This flag is optional.
  468. '                    MIXER_OBJECTF_HWAVEIN (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEIN)-The
  469. '                       uMxId parameter is a waveform-audio input handle returned by the
  470. '                       waveInOpen function.
  471. '                    MIXER_OBJECTF_HWAVEOUT (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEOUT)-The
  472. '                       uMxId parameter is a waveform-audio output handle returned by the
  473. '                       waveOutOpen function.
  474. '                    MIXER_OBJECTF_MIDIIN (&H40000000)-The uMxId parameter is the identifier of
  475. '                       a MIDI input device. This identifier must be in the range of zero to one
  476. '                       less than the number of devices returned by the midiInGetNumDevs function.
  477. '                    MIXER_OBJECTF_MIDIOUT (&H30000000)-The uMxId parameter is the identifier of
  478. '                       a MIDI output device. This identifier must be in the range of zero to one
  479. '                       less than the number of devices returned by the midiOutGetNumDevs function.
  480. '                    MIXER_OBJECTF_MIXER (&H00000000)-The uMxId parameter is a mixer device
  481. '                       identifier in the range of zero to one less than the number of devices
  482. '                       returned by the mixerGetNumDevs function. This flag is optional.
  483. '                    MIXER_OBJECTF_WAVEIN (&H20000000)-The uMxId parameter is the identifier of a
  484. '                       waveform-audio input device in the range of zero to one less than the
  485. '                       number of devices returned by the waveInGetNumDevs function.
  486. '                    MIXER_OBJECTF_WAVEOUT (&H10000000)-The uMxId parameter is the identifier of a
  487. '                       waveform-audio output device in the range of zero to one less than the
  488. '                       number of devices returned by the waveOutGetNumDevs function.
  489.  
  490. Declare Function mixerSetControlDetails Lib "winmm.dll" _
  491.          (ByVal hmxobj As Long, _
  492.          pMxcd As MIXERCONTROLDETAILS, _
  493.          ByVal fdwDetails As Long) As Long
  494. ' The mixerSetControlDetails function sets properties of a single control associated with an
  495. ' audio line. The function uses the following parameters
  496. '     hmxobj-        a long value that is the handle of the mixer device object for which
  497. '                    properties are being set.
  498. '     pMxcd-         the variable declares as the MIXERCONTROLDETAILS user-defined type.
  499. '                    This variable references the control detail structures that contain the
  500. '                    desired state for the control.
  501. '     fdwDetails-    Flags for setting properties for a control. The following values are
  502. '                    defined:
  503. '                    MIXER_OBJECTF_AUX (&H50000000)-The hmxobj parameter is an auxiliary device
  504. '                       identifier in the range of zero to one less than the number of devices
  505. '                       returned by the auxGetNumDevs function.
  506. '                    MIXER_OBJECTF_HMIDIIN (MIXER_OBJECTF_HANDLE or MIXER_OBJECTF_MIDIIN)-
  507. '                       The hmxobj parameter is the handle of a MIDI input device. This handle
  508. '                       must have been returned by the midiInOpen function.
  509. '                    MIXER_OBJECTF_HMIDIOUT (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIOUT)-The
  510. '                       hmxobj parameter is the handle of a MIDI output device. This handle must
  511. '                       have been returned by the midiOutOpen function.
  512. '                    MIXER_OBJECTF_HMIXER (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIXER)-The hmxobj
  513. '                       parameter is a mixer device handle returned by the mixerOpen function.
  514. '                       This flag is optional.
  515. '                    MIXER_OBJECTF_HWAVEIN (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEIN)-The
  516. '                       hmxobj parameter is a waveform-audio input handle returned by the
  517. '                       waveInOpen function.
  518. '                    MIXER_OBJECTF_HWAVEOUT ((MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEOUT)-The
  519. '                       hmxobj parameter is a waveform-audio output handle returned by the
  520. '                       waveOutOpen function.
  521. '                    MIXER_OBJECTF_MIDIIN (&H40000000)-The hmxobj parameter is the identifier
  522. '                       of a MIDI inputdevice. This identifier must be in the range of zero to
  523. '                        one less than the number of devices returned by the midiInGetNumDevs
  524. '                        function.
  525. '                    MIXER_OBJECTF_MIDIOUT (&H30000000)-The hmxobj parameter is the identifier
  526. '                       of a MIDI output device. This identifier must be in the range of zero
  527. '                       to one less than the number of devices returned by the midiOutGetNumDevs
  528. '                       function.
  529. '                    MIXER_OBJECTF_MIXER (&H00000000)-The hmxobj parameter is a mixer device
  530. '                       identifier in the range of zero to one less than the number of devices
  531. '                       returned by the mixerGetNumDevs function. This flag is optional.
  532. '                    MIXER_OBJECTF_WAVEIN (&H20000000)-The hmxobj parameter is the identifier of a
  533. '                       waveform-audio input device in the range of zero to one less than the
  534. '                       number of devices returned by the waveInGetNumDevs function.
  535. '                    MIXER_OBJECTF_WAVEOUT (&H10000000)-The hmxobj parameter is the identifier of a
  536. '                       waveform-audio output device in the range of zero to one less than the
  537. '                       number of devices returned by the waveOutGetNumDevs function.
  538. '                    MIXER_SETCONTROLDETAILSF_CUSTOM-A custom dialog box for the specified
  539. '                       custom mixer control is displayed. The mixer device gathers the required
  540. '                       information from the user and returns the data in the specified buffer.
  541. '                       The handle for the owning window is specified in the hwndOwner member
  542. '                       of the MIXERCONTROLDETAILS structure. (This handle can be set to NULL.)
  543. '                       The application can then save the data from the dialog box and use it
  544. '                       later to reset the control to the same state by using the
  545. '                       MIXER_SETCONTROLDETAILSF_VALUE flag.
  546. '                    MIXER_SETCONTROLDETAILSF_VALUE (&H00000000)-The current value(s) for a control
  547. '                       are set. The paDetails member of the MIXERCONTROLDETAILS structure points
  548. '                       to one or more mixer-control details structures of the appropriate class for
  549. '                       the control.
  550.  
  551. Declare Sub CopyStructFromPtr Lib "kernel32" Alias "RtlMoveMemory" (struct As Any, ByVal ptr As Long, ByVal cb As Long)
  552. Declare Sub CopyPtrFromStruct Lib "kernel32" Alias "RtlMoveMemory" (ByVal ptr As Long, struct As Any, ByVal cb As Long)
  553. ' The CopyStructFromPtr and CopyPtrFromStruct functions are user-defined versions of the
  554. ' RtlMoveMemory function. RtlMoveMemory moves memory either forward or backward, aligned or
  555. ' unaligned, in 4-byte blocks, followed by any remaining bytes. The function requires the
  556. ' following parameters:
  557. '     Destination-   Pointer to the starting address of the copied block's destination.
  558. '     Source-        Pointer to the starting address of the block of memory to copy.
  559. '     Length-        Specifies the size, in bytes, of the block of memory to copy.
  560.  
  561. Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, _
  562.                                              ByVal dwBytes As Long) As Long
  563. ' The GlobalAlloc function allocates the specified number of bytes from the heap.
  564. ' Win32 memory management does not provide a separate local heap and global heap.
  565. ' This function is provided only for compatibility with 16-bit versions of Windows. The function
  566. ' uses the following parameters:
  567. '     wFlags-     a long value that specifies how to allocate memory. If zero is specified,
  568. '                 the default is allocate fixed memory. This value can be one or more of the
  569. '                 following flags:
  570. '                    GMEM_FIXED (&H0)- Allocates fixed memory. The return value is a pointer.
  571. '                    GMEM_MOVEABLE (&H2)- Allocates movable memory. In Win32, memory blocks are
  572. '                       never moved in physical memory, but they can be moved within the default .
  573. '                       The return value is the handle of the memory object. To translate the
  574. '                       heap handle into a pointer, use the GlobalLock function. This flag
  575. '                       cannot be combined with the GMEM_FIXED flag.
  576. '                    GPTR (GMEM_FIXED Or GMEM_ZEROINIT)-Combines the GMEM_FIXED and GMEM_ZEROINIT
  577. '                       flags.
  578. '                    GHND (GMEM_MOVEABLE Or GMEM_ZEROINIT)- Combines the GMEM_MOVEABLE and
  579. '                       GMEM_ZEROINIT flags.
  580. '                    GMEM_ZEROINIT (&H4)-Initializes memory contents to zero.
  581. '     dwBytes-    Specifies the number of bytes to allocate. If this parameter is zero and
  582. '                 the uFlags parameter specifies the GMEM_MOVEABLE flag, the function returns
  583. '                 a handle to a memory object that is marked as discarded.
  584.  
  585. Declare Function GlobalLock Lib "kernel32" (ByVal hmem As Long) As Long
  586. ' The GlobalLock function locks a global memory object and returns a pointer to the first
  587. ' byte of the object's memory block. This function is provided only for compatibility with
  588. ' 16-bit versions of Windows. The function requires a handle to the global memory object. This
  589. ' handle is returned by either the GlobalAlloc or GlobalReAlloc function.
  590.  
  591. Declare Function GlobalFree Lib "kernel32" (ByVal hmem As Long) As Long
  592. ' The GlobalFree function frees the specified global memory object and invalidates its handle.
  593. ' This function is provided only for compatibility with 16-bit versions of Windows. The function
  594. ' requires a h andle to the global memory object. This handle is returned by either the
  595. ' GlobalAlloc or GlobalReAlloc function.
  596.  
  597. Type MIXERCAPS
  598. ' The MIXERCAPS user-defined type contains information about the capabilites of the mixer device.
  599.    wMid As Integer                   '  manufacturer id
  600.    wPid As Integer                   '  product id
  601.    vDriverVersion As Long            '  version of the driver
  602.    szPname As String * MAXPNAMELEN   '  product name
  603.    fdwSupport As Long                '  misc. support bits
  604.    cDestinations As Long             '  count of destinations
  605. End Type
  606.  
  607. Type MIXERCONTROL
  608. ' The MIXERCONTROL user-defined type contains the state and metrics of a single control
  609. ' for an audio line.
  610.    cbStruct As Long           '  size in Byte of MIXERCONTROL
  611.    dwControlID As Long        '  unique control id for mixer device
  612.    dwControlType As Long      '  MIXERCONTROL_CONTROLTYPE_xxx
  613.    fdwControl As Long         '  MIXERCONTROL_CONTROLF_xxx
  614.    cMultipleItems As Long     '  if MIXERCONTROL_CONTROLF_MULTIPLE set
  615.    szShortName As String * MIXER_SHORT_NAME_CHARS  ' short name of control
  616.    szName As String * MIXER_LONG_NAME_CHARS        ' long name of control
  617.    lMinimum As Long           '  Minimum value
  618.    lMaximum As Long           '  Maximum value
  619.    Reserved(10) As Long       '  reserved structure space
  620. End Type
  621.  
  622. Type MIXERCONTROLDETAILS
  623. ' The MIXERCONTROLDETAILS user defined type refers to control-detail structures,
  624. ' retrieving or setting state information of an audio mixer control. All members of this
  625. ' user-defined type must be initialized before calling the mixerGetControlDetails and
  626. ' mixerSetControlDetails functions.
  627.    cbStruct As Long       '  size in Byte of MIXERCONTROLDETAILS
  628.    dwControlID As Long    '  control id to get/set details on
  629.    cChannels As Long      '  number of channels in paDetails array
  630.    item As Long           '  hwndOwner or cMultipleItems
  631.    cbDetails As Long      '  size of _one_ details_XX struct
  632.    paDetails As Long      '  pointer to array of details_XX structs
  633. End Type
  634.  
  635. Type MIXERCONTROLDETAILS_SIGNED
  636. ' The MIXERCONTROLDETAILS_SIGNED user-defined type retrieves and sets signed type control
  637. ' properties for an audio mixer control.
  638.    lValue As Long
  639. End Type
  640.  
  641. Type MIXERLINE
  642. ' The MIXERLINE user-defined type describes the state and metrics of an audio line.
  643.    cbStruct As Long        ' Size of MIXERLINE structure
  644.    dwDestination As Long   ' Zero based destination index
  645.    dwSource As Long        ' Zero based source index (if source)
  646.    dwLineID As Long        ' Unique line id for mixer device
  647.    fdwLine As Long         ' State/information about line
  648.    dwUser As Long          ' Driver specific information
  649.    dwComponentType As Long ' Component type for this audio line.
  650.    cChannels As Long       ' Maximum number of separate channels that can be
  651.                            ' manipulated independently for the audio line.
  652.    cConnections As Long    ' Number of connections that are associated with the
  653.                            ' audio line.
  654.    cControls As Long       ' Number of controls associated with the audio line.
  655.    szShortName As String * MIXER_SHORT_NAME_CHARS  ' Short string that describes
  656.                                                    ' the audio mixer line specified
  657.                                                    ' in the dwLineID member.
  658.    szName As String * MIXER_LONG_NAME_CHARS  ' String that describes the audio
  659.                                              ' mixer line specified in the dwLineID
  660.                                              ' member. This description should be
  661.                                              ' appropriate as a complete description
  662.                                              ' for the line.
  663.    dwType As Long          ' Target media device type associated with the audio
  664.                            ' line described in the MIXERLINE structure.
  665.    dwDeviceID As Long      ' Current device identifier of the target media device
  666.                            ' when the dwType member is a target type other than
  667.                            ' MIXERLINE_TARGETTYPE_UNDEFINED.
  668.    wMid  As Integer        ' Manufacturer identifier of the target media device
  669.                            ' when the dwType member is a target type other than
  670.                            ' MIXERLINE_TARGETTYPE_UNDEFINED.
  671.    wPid As Integer         ' Product identifier of the target media device when
  672.                            ' the dwType member is a target type other than
  673.                            ' MIXERLINE_TARGETTYPE_UNDEFINED.
  674.    vDriverVersion As Long  ' Driver version of the target media device when the
  675.                            ' dwType member is a target type other than
  676.                            ' MIXERLINE_TARGETTYPE_UNDEFINED.
  677.    szPname As String * MAXPNAMELEN  ' Product name of the target media device when
  678.                                     ' the dwType member is a target type other than
  679.                                     ' MIXERLINE_TARGETTYPE_UNDEFINED.
  680. End Type
  681.  
  682. Type MIXERLINECONTROLS
  683. ' The MIXERLINECONTROLS user-defined type contains information about the controls
  684. ' of an audio line.
  685.    cbStruct As Long     ' size in Byte of MIXERLINECONTROLS
  686.    dwLineID As Long     ' Line identifier for which controls are being queried.
  687.    dwControl As Long    ' Control identifier of the desired control
  688.    cControls As Long    ' Number of MIXERCONTROL structure elements to retrieve.
  689.    cbmxctrl As Long     ' Size, in bytes, of a single MIXERCONTROL structure.
  690.    pamxctrl As Long     ' Address of one or more MIXERCONTROL structures to receive
  691.                         '  the properties of the requested audio line controls.
  692. End Type
  693.  
  694. Public i As Integer
  695. Public j As Integer
  696. Public rc As Long
  697. Public msg As String * 200
  698. Public hWaveIn As Long
  699. Public format As WAVEFORMAT
  700.  
  701. Public Const NUM_BUFFERS = 2
  702. Public Const BUFFER_SIZE = 8192
  703. Public Const DEVICEID = 0
  704. Public hmem(NUM_BUFFERS) As Long
  705. Public inHdr(NUM_BUFFERS) As WAVEHDR
  706.  
  707. Public fRecording As Boolean
  708.  
  709. Function GetControl(ByVal hmixer As Long, ByVal componentType As Long, ByVal ctrlType As Long, ByRef mxc As MIXERCONTROL) As Boolean
  710. ' This function attempts to obtain a mixer control. Returns True if successful.
  711.  
  712.    Dim mxlc As MIXERLINECONTROLS
  713.    Dim mxl As MIXERLINE
  714.    Dim hmem As Long
  715.    Dim rc As Long
  716.        
  717.    mxl.cbStruct = Len(mxl)
  718.    mxl.dwComponentType = componentType
  719.    
  720.    ' Obtain a line corresponding to the component type
  721.    rc = mixerGetLineInfo(hmixer, mxl, MIXER_GETLINEINFOF_COMPONENTTYPE)
  722.    
  723.    If (MMSYSERR_NOERROR = rc) Then
  724.       mxlc.cbStruct = Len(mxlc)
  725.       mxlc.dwLineID = mxl.dwLineID
  726.       mxlc.dwControl = ctrlType
  727.       mxlc.cControls = 1
  728.       mxlc.cbmxctrl = Len(mxc)
  729.       
  730.       ' Allocate a buffer for the control
  731.       'hmem = GlobalAlloc(&H40, Len(mxc))
  732.       hmem = GlobalAlloc(GMEM_FIXED, Len(mxc))
  733.       mxlc.pamxctrl = GlobalLock(hmem)
  734.       mxc.cbStruct = Len(mxc)
  735.       
  736.       ' Get the control
  737.       rc = mixerGetLineControls(hmixer, mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)
  738.             
  739.       If (MMSYSERR_NOERROR = rc) Then
  740.          GetControl = True
  741.          
  742.          ' Copy the control into the destination structure
  743.          CopyStructFromPtr mxc, mxlc.pamxctrl, Len(mxc)
  744.       Else
  745.          GetControl = False
  746.       End If
  747.       GlobalFree (hmem)
  748.       Exit Function
  749.    End If
  750.    
  751.    GetControl = False
  752. End Function
  753.  
  754. ' Function to process the wave recording notifications.
  755. Sub waveInProc(ByVal hwi As Long, ByVal uMsg As Long, ByVal dwInstance As Long, ByRef hdr As WAVEHDR, ByVal dwParam2 As Long)
  756.    If (uMsg = MM_WIM_DATA) Then
  757.       If fRecording Then
  758.          rc = waveInAddBuffer(hwi, hdr, Len(hdr))
  759.       End If
  760.    End If
  761. End Sub
  762.  
  763. ' This function starts recording from the soundcard. The soundcard must be recording in order to
  764. ' monitor the input level. Without starting the recording from this application, input level
  765. ' can still be monitored if another application is recording audio
  766. Function StartInput() As Boolean
  767.  
  768.     If fRecording Then
  769.         StartInput = True
  770.         Exit Function
  771.     End If
  772.     
  773.     format.wFormatTag = 1
  774.     format.nChannels = 1
  775.     format.wBitsPerSample = 8
  776.     format.nSamplesPerSec = 8000
  777.     format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8
  778.     format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign
  779.     format.cbSize = 0
  780.     
  781.     For i = 0 To NUM_BUFFERS - 1
  782.         hmem(i) = GlobalAlloc(&H40, BUFFER_SIZE)
  783.         inHdr(i).lpData = GlobalLock(hmem(i))
  784.         inHdr(i).dwBufferLength = BUFFER_SIZE
  785.         inHdr(i).dwFlags = 0
  786.         inHdr(i).dwLoops = 0
  787.     Next
  788.  
  789.     rc = waveInOpen(hWaveIn, DEVICEID, format, 0, 0, 0)
  790.     If rc <> 0 Then
  791.         waveInGetErrorText rc, msg, Len(msg)
  792.         MsgBox msg
  793.         StartInput = False
  794.         Exit Function
  795.     End If
  796.  
  797.     For i = 0 To NUM_BUFFERS - 1
  798.         rc = waveInPrepareHeader(hWaveIn, inHdr(i), Len(inHdr(i)))
  799.         If (rc <> 0) Then
  800.             waveInGetErrorText rc, msg, Len(msg)
  801.             MsgBox msg
  802.         End If
  803.     Next
  804.  
  805.     For i = 0 To NUM_BUFFERS - 1
  806.         rc = waveInAddBuffer(hWaveIn, inHdr(i), Len(inHdr(i)))
  807.         If (rc <> 0) Then
  808.             waveInGetErrorText rc, msg, Len(msg)
  809.             MsgBox msg
  810.         End If
  811.     Next
  812.  
  813.     fRecording = True
  814.     rc = waveInStart(hWaveIn)
  815.     StartInput = True
  816. End Function
  817.  
  818. ' Stop receiving audio input on the soundcard
  819. Sub StopInput()
  820.  
  821.     fRecording = False
  822.     waveInReset hWaveIn
  823.     waveInStop hWaveIn
  824.     For i = 0 To NUM_BUFFERS - 1
  825.         waveInUnprepareHeader hWaveIn, inHdr(i), Len(inHdr(i))
  826.         GlobalFree hmem(i)
  827.     Next
  828.     waveInClose hWaveIn
  829. End Sub
  830.